<template>
  <div class="login-page">
    <div class="head">
      <!-- <dv-decoration-5 style="width:100%;height:100px;" />
      <div class="title">工业互联网纺织大数据管理中心1</div> -->
    </div>
    <el-form
      ref="loginForm"
      :model="loginForm"
      :rules="loginRules"
      class="login-form"
      auto-complete="on"
      label-position="left"
    >
      <div class="title-container">
        <h3 class="title">欢迎登录</h3>
      </div>
      <el-form-item prop="username" class="display">
        <img src="@/assets/img/user.png" alt="" class="img-user-png" />
        <el-input
          v-model="loginForm.username"
          placeholder="请输入用户名"
          name="admin_account"
          type="text"
          auto-complete="off"
        />
      </el-form-item>
      <el-form-item prop="password" class="display">
        <img src="@/assets/img/password.png" alt="" class="img-password-png" />
        <el-input
          v-model="loginForm.password"
          type="password"
          placeholder="请输入密码"
          name="admin_password"
          auto-complete="off"
          @keyup.enter.native="handleLogin('loginForm')"
        />
      </el-form-item>
      <div class="btnBox">
        <el-button
          :loading="loading"
          type="primary"
          class="sumit-btn"
          style="width: 100%;margin-top:40px;height:50px"
          @click.native.prevent="handleLogin('loginForm')"
          >登录</el-button
        >
      </div>
    </el-form>
  </div>
</template>
<script>
import MES from "@/utils/mesUtils";
export default {
  data() {
    const validateUsername = (rule, value, callback) => {
      if (!value) {
        callback(new Error("请输入用户名"));
      } else {
        callback();
      }
    };
    const validatePassword = (rule, value, callback) => {
      if (value.length < 6) {
        callback(new Error("密码不能小于6位"));
      } else {
        callback();
      }
    };
    return {
      loginForm: {
        username: "",
        password: "",
      },
      loginRules: {
        username: [
          { required: true, trigger: "blur", validator: validateUsername },
        ],
        password: [
          { required: true, trigger: "blur", validator: validatePassword },
        ],
      },
      loading: false,
    };
  },
  methods: {
    handleLogin(name) {
      this.$refs[name].validate((valid) => {
        if (valid) {
          this.loading = true;
          MES.queryLogin(this.loginForm)
            .then((res) => {
              if (res.code === 1) {
                localStorage.setItem("mvToken", res.data);
                setTimeout(() => {
                  this.$router.push({ name: "Index" });
                  this.loading = false;
                }, 300);
              } else {
                this.loading = false;
                this.$notify.error({
                  title: "错误",
                  message: res.data,
                });
              }
            })
            .catch((error) => {
              this.loading = false;
            });
        }
      });
    },
  },
};
</script>
<style lang="scss">
.login-page {
  height: 100vh;
  position: relative;
  background: url(../../assets/img/login_bg.png) no-repeat;
  background-size: 100% 100%;
  .head {
    position: relative;
    background: url(../../assets/img/login_head.png) no-repeat;
    background-size: 100% 100%;
    width: 100%;
    height: 69px;
    .title {
      position: absolute;
      left: 50%;
      transform: translateX(-50%);
      top: 10px;
      font-size: 35px;
      font-family: SourceHanSansCN-Bold, SourceHanSansCN;
      font-weight: bold;
      color: #ffffff;
      line-height: 53px;
      text-shadow: 0px 2px 8px #1d4248;
    }
  }
  .login-form {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    right: 185px;
    width: 400px;
    height: 500px;
    // border: 1px solid #eee;
    padding: 0 43px;
    box-sizing: border-box;
    background: url(../../assets/img/login_border.png) no-repeat;
    background-size: 100% 100%;
    .title-container {
      margin-top: 60px;
      .title {
        font-size: 34px;
        color: #23e2ff;
        text-align: center;
      }
      margin-bottom: 70px;
    }
    .el-form-item__content {
      display: flex !important;
      align-items: center;
      height: 56px;
      background: rgba(7, 23, 57, 0.75);
      border-radius: 4px;
      padding: 0 20px;
      box-sizing: border-box;
    }
    .img-user-png,
    .img-password-png {
      width: 24px;
      height: 24px;
    }
    input {
      border: 0;
      font-size: 18px;
      color: #ffffff;
      background: transparent;
    }
    .sumit-btn {
      height: 56px;
      background: linear-gradient(180deg, #00c8da 0%, #0092a4 100%);
      border-radius: 4px;
    }
  }
}
</style>
